<?php

$link = mysqli_connect('localhost', 'root', '123', 'Dress', '3306');
mysqli_query($link,"set names 'utf8'");

if(isset($_POST["revise1"])) {
    $id = $_POST['username'];
    $sql = "select * from user where username = '$id'";
    $result = mysqli_query($link,$sql);
    $row = mysqli_fetch_array($result);
    $username = !empty($_POST['username']) ? $_POST['username'] : $row[0];
    $password = !empty($_POST['password']) ? $_POST['password'] : $row[1];
    $name = !empty($_POST['name']) ? $_POST['name'] : $row[2];
    $age = !empty($_POST['age']) ? $_POST['age'] : $row[3];
    $sex = !empty($_POST['sex']) ? $_POST['sex'] : $row[6];
    $phone = !empty($_POST['phone']) ? $_POST['phone'] : $row[5];
    $address = !empty($_POST['address']) ? $_POST['address'] : $row[4];
    mysqli_query($link,"update user set username='$username',password='$password',realname='$name',age='$age',sex='$sex',phonenum='$phone',address='$address' where username = '$id'");
    echo "<script>alert('修改成功！'); window.location= 'member-list.php';</script>";
}

if(isset($_POST["revise2"])) {
    $id = $_POST['title'];
    $sql = "select * from goods where name = '$id'";
    $result = mysqli_query($link,$sql);
    $row = mysqli_fetch_array($result);
    $name = !empty($_POST['title']) ? $_POST['title'] : $row[0];
    $price = !empty($_POST['price']) ? $_POST['price'] : $row[1];
    $type = !empty($_POST['type']) ? $_POST['type'] : $row[5];
    $num = !empty($_POST['num']) ? $_POST['num'] : $row[4];
    $intro = !empty($_POST['intro']) ? $_POST['intro'] : $row[3];
    $array=explode('/', $row[2]);
    $pic = !empty($_POST['pic']) ? $_POST['pic'] : $array[5];
    $pic= substr_replace($pic,"lib/webuploader/0.1.5/server/goods/",0,0);
    $res_insert = mysqli_query($link,"update goods set name='$name',price='$price',pic='$pic',type='$type',num='$num',introduction='$intro' where name = '$id'");
    if ($res_insert) {
        echo "<script>alert('修改成功！'); window.location= 'goods-list.php';</script>";
    } else {
        echo "<script>alert('系统繁忙，请稍候！');history.go(-1); </script>";
    }
}

if(isset($_POST["revise3"])) {
    $id = $_POST['title'];
    $sql = "select * from style where title = '$id'";
    $result = mysqli_query($link,$sql);
    $row = mysqli_fetch_array($result);
    $title = !empty($_POST['title']) ? $_POST['title'] : $row[0];
    $type = !empty($_POST['type']) ? $_POST['type'] : $row[3];
    $intro = !empty($_POST['intro']) ? $_POST['intro'] : $row[2];
    $array=explode('/', $row[1]);
    $pic = !empty($_POST['pic']) ? $_POST['pic'] : $array[5];
    $pic= substr_replace($pic,"lib/webuploader/0.1.5/server/style/",0,0);
    $res_insert = mysqli_query($link,"update style set title='$title',pic='$pic',type='$type',introduce='$intro' where title = '$id'");
    if ($res_insert) {
        echo "<script>alert('修改成功！'); window.location= 'style-list.php';</script>";
    } else {
        echo "<script>alert('系统繁忙，请稍候！');history.go(-1); </script>";
    }
}
?>